import imgaug as ia
from imgaug import augmenters as iaa
import numpy as np

class ImgAugTransform():
    def __init__(self):
        self.aug = iaa.Sequential([
            #iaa.Fliplr(0.5) # 水平反转 0.5概率
            #iaa.Flipud(0.5) # 竖直反转
            #iaa.CoarseDropout((0.01,0.02),size_percent=(0.15,0.25)),
            iaa.PiecewiseAffine(scale=(0.05,0.1)), # 扭曲图像局部区域
            iaa.Crop(percent=(0,0.1)), # 中心裁减
            
            #iaa.Sharpen(alpha=(0,1.0)) # 图片锐利化
            #iaa.Emboss(alpha=(0,1.0),strength=(0,2.0)) # 凹凸印
            
            #iaa.Dropout((0.1,0.5))
            iaa.Affine(scale={"x":(0.5,1.0),"y":(0.5,1.0)}, 
                translate_percent={"x":(-0.2,0.2),"y":(-0.2,0.2)},
                rotate=(-25,25), 
                shear=(-8,8))
        ])
    
    def __call__(self,img):
        img = np.array(img)
        return self.aug.augment_images(img)